FROM golang:1.21.11-alpine3.20 AS builder

LABEL stage=gobuilder

ARG BUILD_ENV

ENV CGO_ENABLED 0
ENV GOPROXY https://goproxy.cn,direct
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

RUN apk update --no-cache && apk add --no-cache tzdata

WORKDIR /build

ADD app/user/rpc/go.mod .
ADD app/user/rpc/go.sum .
RUN go env -w GOPROXY='https://goproxy.cn,direct'
RUN go mod download
COPY app/user/rpc .
COPY app/user/rpc/etc /app/etc
RUN go build -ldflags="-s -w" -o /app/user main.go


FROM scratch

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai

ARG BUILD_ENV

ENV TZ Asia/Shanghai
ENV BUILD_ENV $BUILD_ENV

WORKDIR /app
COPY --from=builder /app/user /app/user
COPY --from=builder /app/etc /app/etc

CMD ["./user"]
